package com.liu.system.manage.controller;

import com.liu.common.domain.ResultVo;
import com.liu.common.utils.JacksonUtil;
import com.liu.system.manage.domain.DMenu;
import com.liu.system.manage.domain.Option;
import com.liu.system.manage.domain.TreeNode;
import com.liu.system.manage.service.IMenuService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Slf4j
@RestController
@RefreshScope
@RequestMapping("/vue-admin-template/menu")
@CrossOrigin
public class MenuController {


    @Autowired
    IMenuService menuService;


    @GetMapping("/getTree")
    public ResultVo getMenuTree(String query){




     List<TreeNode> tree = menuService.getMenuTree(query,"1");



        return  ResultVo.success(tree);
    }

    @GetMapping("/getOptions")
    public ResultVo getOptions(){
        List<Option> options= menuService.getOptions();
        return ResultVo.success(options);
    }


   @PostMapping
    public ResultVo addMenu(@RequestBody DMenu menu){

        log.info("接受到的参数为"+JacksonUtil.printJson(menu));
          menuService.addMenu(menu);

        return ResultVo.success("添加菜单成功");
    }

    @PutMapping
    public ResultVo update(@RequestBody DMenu menu){

        log.info("接受到的参数为"+JacksonUtil.printJson(menu));
        menuService.updateMenu(menu);

        return ResultVo.success("修改菜单成功");
    }

    @DeleteMapping
    public ResultVo delete(@RequestBody DMenu menu){


        menuService.delete(menu.getId());

        return ResultVo.success("菜单删除成功！！");
    }




}
